var express = require("express");
var router = express.Router();
const PersonController = require("../controllers/PersonController");
const multer = require("multer");
const upload = multer({ dest: "public/uploads" });

/* GET users listing. */
router.get("/", function (req, res, next) {
  res.send("respond with a resource");
});
/**
 *
 * @api {get} /api/person/add 新增用户
 * @apiName addPerson
 * @apiGroup 用户管理
 * @apiVersion  1.0.0
 *
 *
 * @apiParam  {String} username 用户名
 * @apiParam  {Number} age 年龄
 * @apiParam  {String} password 密码
 * @apiParam  {File} avatar 头像
 *
 * @apiSuccess (200) {String} status 标识
 *
 * @apiParamExample  {multipart/form-data} Request-Example:
 * {
 *     username: 'xiaoming',
 *     age: 1,
 *     password: '123',
 *     avatar: '/images/default'
 * }
 *
 *
 * @apiSuccessExample {json} Success-Response:
 * {
 *     status: 'success',
 *     data: {
 *          _id: 'xxxx',
 *          username: 'xiaoming',
 *          age: 1,
 *          password: '123',
 *          avatar: '/images/default',
 *          _o: 0
 *     }
 * }
 *
 *
 */
// 新增
router.post("/person/add", upload.single("avatar"), PersonController.addPerson);

/**
 *
 * @api {put} /api/person/update 更新用户
 * @apiName updatePerson
 * @apiGroup 用户管理
 * @apiVersion  1.0.0
 *
 *
 * @apiParam  {String} username 用户名
 * @apiParam  {Number} age 年龄
 * @apiParam  {String} password 密码
 * @apiParam  {File} avatar 头像
 *
 * @apiSuccess (200) {String} status 标识
 *
 * @apiParamExample  {multipart/form-data} Request-Example:
 * {
 *     username: 'xiaoming',
 *     age: 1,
 *     password: '123',
 *     avatar: '/images/default',
 *     _id: 'xxxx',
 *     _o: 0,
 * }
 *
 *
 * @apiSuccessExample {json} Success-Response:
 * {
 *     status: 'success',
 *     data: {
 *          _id: 'xxxx',
 *          username: 'xiaoming',
 *          age: 1,
 *          password: '123',
 *          avatar: '/images/default',
 *          _o: 0
 *     }
 * }
 *
 *
 */
// 更新个人
router.put("/person/update", PersonController.updatePerson);

// 查询列表、个人
router.get("/person/list(/:id)?", PersonController.getPersonOrList);

// 删除个人
router.delete("/person/del/:id", PersonController.delPerson);

// 登录界面 登录
router.post("/login", PersonController.login);
// 退出登录
router.get("/logout", PersonController.logout);

module.exports = router;
